
package View;

import IO.ResourceCharacterLocation;
import java.awt.Component;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
        
public class AddCharacterForm extends javax.swing.JFrame {
    
    MainMenu mainWindow;
    String Globalname="";
    public ArrayList<ArrayList<Object>> characterList = null;
    public String selectedCharacterType = "";

    public AddCharacterForm(MainMenu main) {

            mainWindow = main;
            initComponents();
            ResourceCharacterLocation checker = new ResourceCharacterLocation();
            //ArrayList<ArrayList<Object>> characterList = checker.loadImgCharactersArrayList();
            characterList = checker.loadImgCharactersArrayList();
            addImages(characterList);
        
    }
    
    //Add the character buttons to the form
    private void addImages(ArrayList<ArrayList<Object>> characterList){
        jPanel1.setLayout(new BoxLayout(jPanel1, BoxLayout.Y_AXIS));
        
       for(int x=0; x<characterList.size();x++){
            JButton button = new JButton("");
            button.setAlignmentX(Component.CENTER_ALIGNMENT);
            ArrayList<Object> characterData = characterList.get(x);
            System.out.println(characterData.get(2).toString());
            setImageToButton(button, characterData.get(2).toString());
            selectedCharacterType = characterData.get(1).toString();
            jPanel1.add(button); 
            button.addMouseListener(new PageActionListener(characterData.get(2).toString(), mainWindow, this));
            jPanel1.add(button);  
        }
    }
    
    //Set the images to the buttons
    private void setImageToButton(JButton button, String imagePath){
        ImageIcon imgIcn = (new javax.swing.ImageIcon((imagePath)));
        button.setIcon(new ImageIcon(imgIcn.getImage().getScaledInstance(300, 300, Image.SCALE_SMOOTH)));
        button.setOpaque(false);
        button.setContentAreaFilled(false);
        button.setBorderPainted(false);  
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(java.awt.Color.white);
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Trebuchet MS", 0, 24)); // NOI18N
        jLabel1.setText("Selecciona el personaje:");

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setToolTipText("");

        jPanel1.setBackground(java.awt.Color.white);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 432, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 343, Short.MAX_VALUE)
        );

        jScrollPane2.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables
}
